import { ElMessage, ElMessageBox } from 'element-plus'
// 确认弹窗
export function useConfirm({
  title = 'Title',
  tps = '提示',
  type = '',
  confirmButtonText = '确定',
  cancelButtonText = '取消',
  customClass = 'confirm-custom-class',
  showCancelButton = true,
  dangerouslyUseHTMLString = false
}) {
  return ElMessageBox.confirm(title, tps, {
    confirmButtonText,
    cancelButtonText,
    showCancelButton,
    type,
    dangerouslyUseHTMLString,
    customClass
  })
}

// 删除确认弹窗
export function useDeleteConfirm(title: string = '确认要删除记录?') {
  return new Promise((resolve, reject) => {
    useConfirm({
      title,
      tps: '提示',
      customClass: 'messegeTxt',
      type: 'warning'
    })
      .then(() => resolve(true))
      .catch(() => reject(false))
  })
}

// 判断文件类型
export function fileType(file: string) {
  if (file) file = file.toLowerCase()
  let type = 'other'
  let pdfReg = /^.+(\.pdf)$/,
    txtReg = /^.+(\.txt)$/,
    wordReg = /^.+(\.doc|\.docx)$/,
    excelReg = /^.+(\.xls|\.xlsx)$/,
    jpgReg = /^.+(\.png|\.jpg|\.jpeg|\.bmp|\.gif|\.icon|\.jfif|\.JFIF)$/,
    bimReg = /^.+(\.rvt|\.rfa|\.dwg|\.dxf|\.spk|\.ifc|\.dgn|\.obj|\.stl|\.3ds|\.dae|\.ply|\.igms|\.zip|\.fbx|\.dwf|\.nwd|\.bmv)$/,
    video = /^.+(\.mov|\.mp4)$/
  if (pdfReg.test(file)) type = 'pdf'
  if (txtReg.test(file)) type = 'txt'
  if (wordReg.test(file)) type = 'word'
  if (excelReg.test(file)) type = 'excel'
  if (jpgReg.test(file)) type = 'picture'
  if (bimReg.test(file)) type = 'bim'
  if (video.test(file)) type = 'video'
  return type
}

// PDF预览
export const previewPdf = (url: string) => window.open('/static/pdf/web/viewer.html?file=' + url)
